

/**布局管理器，用于延迟布局，此游戏没有多大用处**/	
	class LayoutManager
	{
		private static _disposed:boolean;
		public static dispose():void
		{
			if(LayoutManager._disposed)			
				return;
			
			LayoutManager._disposed = true;
			LayoutManager.__stage = null;
			LayoutManager.__timer = null;
			LayoutManager.__renderFuncList = null;
			LayoutManager.__tempRenderFuncList = null;
		}
		protected static __renderFuncList;
		protected static __tempRenderFuncList;
		protected static __rending:Boolean=false;
		protected static __stage:Laya.Stage;
		protected static __timer:Laya.Timer;
		public static max:number=0;
		public static lastNum:number=0;
		public static Init(stage:Laya.Stage):void
		{
			var s = this;
			LayoutManager.__stage=stage;
			LayoutManager.__timer = new Laya.Timer;
			LayoutManager.__renderFuncList = [];
			LayoutManager.__tempRenderFuncList = [];
		}
		/**
		 * 舞台渲染前执行
		 * */
		public static addRenderFunc(up:any/*:IUpdate*/):void
		{
			var s = this;
			if(up==null)
				return;
			if(up.updating)return;
			if(LayoutManager.__rending)
				LayoutManager.__tempRenderFuncList.push(up);
			else
				LayoutManager.__renderFuncList.push(up);
			up.updating = true;
			if(LayoutManager.__renderFuncList.length > 1)return;
			// LayoutManager.__stage.invalidate();
			// LayoutManager.__stage.on(Laya.Event.RENDER,LayoutManager.__stage,LayoutManager.RenderFunc);
			LayoutManager.__timer.callLater(null,LayoutManager.RenderFunc)
		}
		private static RenderFunc(e:Event=null):void
		{
			var len:number;
			var up:any/*:IUpdate*/;
			var t:Number;
			LayoutManager.__rending = true;
			LayoutManager.update(LayoutManager.__renderFuncList);			
			LayoutManager.__rending = false;
		}
		private static update(vec):void
		{
			var len:number;
			var up:any/*:IUpdate*/;
			var tempVec;
			if(LayoutManager._disposed)return;
			LayoutManager.__rending = true;
			len=LayoutManager.__renderFuncList.length;
			if(LayoutManager.max < len)LayoutManager.max = len;
			LayoutManager.lastNum = len;
			while(--len > -1)
			{
				up = LayoutManager.__renderFuncList[len];
				up.updating = false;
				up.updateView();				
			}		
			LayoutManager.__renderFuncList.length = 0;			
			len = LayoutManager.__tempRenderFuncList.length;
			if(len > 0)
			{
				tempVec = LayoutManager.__renderFuncList;
				LayoutManager.__renderFuncList = LayoutManager.__tempRenderFuncList;
				LayoutManager.__tempRenderFuncList = tempVec;
				LayoutManager.update(LayoutManager.__renderFuncList);
			}
		}
	}
